#include "header.hpp"
using namespace std;

//atomic data type
//keep all operations to this type's data is atomic
/* CAS(Compare And Set/Swap): Compare value V in memory and anticpiate value A
 * if V is equal to A, this thread can update value to B
 * if V is not equal to A, it means other thread has modified this value, so this thread cannot update the value
*/
atomic<int> global2(0);

void threadFunc3(){
    for(size_t i = 0; i < 10000000; ++i){
        ++global2;
    }
}

void test15(){
    thread t1(threadFunc3);
    thread t2(threadFunc3);

    t1.join();
    t2.join();

    cout << "global2 = " << global2 << endl;
}
